import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class Language extends StatelessWidget {
  const Language({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    void _incrementCounter() {
      showModalBottomSheet(
          context: context,
          builder: (_) => Container(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    ListTile(
                      title: Text("chinese".tr),
                      onTap: () async {
                        var locale = Locale('zh', 'CN');
                        await Get.updateLocale(locale);
                        Navigator.pop(context);
                      },
                    ),
                    ListTile(
                      title: Text("english".tr),
                      onTap: () async {
                        var locale = Locale('en', 'US');
                        await Get.updateLocale(locale);
                        Navigator.pop(context);
                      },
                    ),
                  ],
                ),
              ));
    }

    return Scaffold(
      appBar: AppBar(
        title: Text("setting_language".tr),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              '当前的语言为: ${Get.locale}',
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'setting_language'.tr,
        child: const Icon(Icons.add),
      ),
    );
  }
}
